﻿using D.Domain.SeedWork.EventUtil;

namespace D.Domain.SeedWork
{
    /// <summary>
    /// 标识性接口，表示聚合根
    /// </summary>
    public abstract class AggregateRoot : BaseEntity
    {
        private readonly List<DomainEvent> _changes;

        /// <summary>
        /// 某个实体对象改变
        /// </summary>
        /// <param name="event"></param>
        protected void ApplyChange(DomainEvent @event)
        {
            ApplyChange(@event, true);
        }

        private void ApplyChange(DomainEvent @event, bool isNew)
        {
            dynamic d = this;
            d.Handle(@event);
            if (isNew)
            {
                _changes.Add(@event);
            }
        }
    }
}
